package com.yiwei.hdb.api.requestInfo;

import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.ApplyForBean;
import com.yiwei.hdb.api.callback.ApplyForContract;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class ApplyForRequest extends BaseRequest<ApplyForContract.View> implements ApplyForContract.Presenter<ApplyForContract.View> {

    public static ApplyForRequest create() {
        return new ApplyForRequest();
    }

    @Override
    public void getBankList() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        Api.api_service.getBankList().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getBankListSuccess(result);
                });
    }

    @Override
    public void getApplyForInfo(String deal_id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        ApplyForBean bean = new ApplyForBean();
        bean.deal_id = deal_id;
        Api.api_service.getApplyForInfo(bean).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if(result.getStatus()==1){
                        mView.getApplyForInfoSuccess(result);
                    }else {
                      mView.getApplyForInfoFail(result.getMsg());
                    }
                });
    }
}
